package com.burgeon.backend.SHOPBACKEND.service.Impl;

import com.burgeon.backend.SHOPBACKEND.entity.BirthdayConfiguration;
import com.burgeon.backend.SHOPBACKEND.entity.Goods;
import com.burgeon.backend.SHOPBACKEND.mappers.BackendBirthdayDeployMapper;
import com.burgeon.backend.SHOPBACKEND.service.BackendBirthdayDeployService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class BackendBirthdayDeployServiceImpl implements BackendBirthdayDeployService {

    @Autowired
    private BackendBirthdayDeployMapper backendBirthdayDeployMapper;

    @Override
    public HashMap findIntegralGoods(String account, String flag, String message) {
        HashMap data = new HashMap();
        List<Goods> goodsInfo = backendBirthdayDeployMapper.findIntegralGoods(account, flag, message);
        BirthdayConfiguration birthdayConfiguration = backendBirthdayDeployMapper.findBirthdayConfiguration(account);
        data.put("goodsInfo",goodsInfo);
        data.put("isOpen",birthdayConfiguration.getIsOpen());
        data.put("couponTypeId",birthdayConfiguration.getCouponTypeId());
        data.put("getWay",birthdayConfiguration.getGetWay());
        return data;
    }

    /*@Override
    public Goods findGoodsData(String account, String goodId) {
        return backendBirthdayDeployMapper.findGoodsData(account,goodId);
    }*/

    @Override
    public void updateActivityIntegral(String account, String goodId, String activityIntegral) {
        backendBirthdayDeployMapper.updateActivityIntegral(account,goodId,activityIntegral);
    }

    @Override
    public void updateIsShow(String account, String goodId, String isShow) {
        backendBirthdayDeployMapper.updateIsShow(account,goodId,isShow);
    }

    @Override
    public void updateBirthdayConfiguration(String token, Integer couponTypeId, String isOpen, String getWay) {

        BirthdayConfiguration birthdayConfiguration =backendBirthdayDeployMapper.findBirthdayConfiguration(token);

        if (birthdayConfiguration != null){
            backendBirthdayDeployMapper.updateBirthdayConfiguration(token,couponTypeId,isOpen,getWay);
        }else {
            backendBirthdayDeployMapper.insertBirthdayConfiguration(token,couponTypeId,isOpen,getWay);
        }

    }
}
